package cn.chinaunicom.service.test;

import cn.chinaunicom.service.DemoServiceApplication;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.test.context.junit4.SpringRunner;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;

@Slf4j
@RunWith(SpringRunner.class)
@ComponentScan(basePackages = {"com.*"})
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = DemoServiceApplication.class)
public class DemoTest01 {
    @Value("${info.addr}")
    private String addr;

    @Test
    public void test1() {
        log.info("====addr====" + addr);
        log.info("====addr====" + addr);
        log.info("====addr====" + addr);
        log.info("====addr====" + addr);
        HashMap hashMap = new HashMap();
        hashMap.put("1", "1");
        hashMap.put("2", "2");
        hashMap.put("3", "3");
        hashMap.put("4", "4");
        hashMap.put("5", "5");
        hashMap.put("6", "6");

        String a = "2019-01-01";
        ArrayList  list = new ArrayList();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        /*查询时间段内的所有日期*/
        try {
            Date date = sdf.parse(a);
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            while (true) {
                String time = sdf.format(calendar.getTime());
                list.add(time);
                calendar.add(Calendar.DAY_OF_MONTH, 1);
                if (calendar.getTime().getTime() > new Date().getTime()) {
                    break;
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }

        log.info("====list====" + list);
        /*查询redis中是否有key*/
        for (int i = 0; i < list.size(); i++) {
            String key = list.get(i).toString();
            log.info("====key====" + key);
            if (hashMap.containsKey(key)) {
                log.info("====key====" + key);
            }
        }



    }


}
